<template>
	<view class="container  bg">

		<template v-if="type==1">
			<view class="t">你的身份是？</view>
			<view class="t1">帮助我们更好地为你提供服务</view>
			<view class="identity">
				<image src="/static/img/parent-bg.png"></image>
				<view class="identity-name">
					<view class="identity-name-pinyin">jia zhang</view>
					<view class="identity-name-text">家长</view>
				</view>
				<button size="default" open-type="getPhoneNumber" @getphonenumber="(e)=>getPhoneNumber(e,0)"
					class="login"></button>
			</view>
			<view class="identity">
				<image src="/static/img/teacher-bg.png"></image>
				<view class="identity-name">
					<view class="identity-name-pinyin">lao shi</view>
					<view class="identity-name-text">老师</view>
				</view>
				<button size="default" open-type="getPhoneNumber" @getphonenumber="(e)=>getPhoneNumber(e,1)"
					class="login"></button>
			</view>
		</template>

		<template v-else>
			<view class="t">确认学生信息</view>
			<view class="list">
				<view class="list-item" :class="{selected:true}" v-for="item in 3">
					<view class="list-item-name">小夜曲</view>
					<image class="list-item-sex" src="/static/img/ic-sex-0.png"></image>
					<view class="list-item-school">哈尔滨学校名称</view>
					<view class="list-item-class">三年二班</view>
					<view class="list-item-number">231089199904221234</view>
					<image class="list-item-head" src="/static/img/head.png"></image>
				</view>
			</view>
			<view class="btn">
				<view class="btn-error" @click="error">信息有误</view>
				<view class="btn-confirm" @click="confirm">确认</view>
			</view>
		</template>


	</view>
</template>
<script>
	import { login } from '@/api/login.js'
	export default {
		components: {

		},
		data() {
			return {
				type: 1, //1选择身份  2确认学生信息
				list: [], //家长关联的学生列表

			};
		},
		mounted() {


		},
		onShow() {},
		methods: {
			//信息有误提示
			error() {
				uni.showModal({
					title: '提示',
					content: '匹配到学生信息不符，请联系教师',
					cancelText: '取消',
					showCancel: false,
					confirmText: '取消'
				});
			},

			//家长确认学生
			confirm() {
				uni.navigateTo({
					url: '/pages/student/index'
				})
			},
			//获取手机号回调
			async getPhoneNumber(e, type) {
				try {
					//获取微信code
					const res = await uni.login({ provider: 'weixin', });
					//手机号code和登录code 获取对应的用户token
					const tokenRes = await login({code: res[1].code,phoneCode: e.detail.code});
					this.toast('登录成功')
					//0家长端 1教
					if (type == 0) {
						//家长确认学生界面
						this.type = 2;
					} else {
						//教师首页
						uni.navigateTo({
							url: '/pages/teacher/index'
						})
					}
				} catch (e) {
					console.error(e);
					this.toast('登录失败')
				}
			}
		},
	};
</script>
<style lang="scss" scoped>
	.is-hover {
		color: rgba(255, 255, 255, 0.6);
		background-color: #179b16;
		border-color: #179b16;
	}

	.login {
		color: #ffffff;
		background: transparent;
		position: absolute;
		top: 0;
		width: 648rpx;
		height: 232rpx;

		&:active {
			border: #179b16 solid 2rpx;

		}
	}

	.t {
		margin-left: 40rpx;
		font-weight: bold;
		margin-top: 14vh;
		font-size: 52rpx;
		color: $uni-color-title;
	}

	.t1 {
		margin-left: 40rpx;
		margin-top: 20rpx;
		font-size: 30rpx;
		color: $uni-color-title;
	}

	.btn {
		display: flex;
		margin-top: 50rpx;
		justify-content: space-around;

		&-error {
			@include btnRadius();
			width: 256rpx;
			color: #38CDB0;
			background: #FFFFFF;
			box-sizing: border-box;
			border: 1rpx solid #38CDB0;
		}

		&-confirm {
			@include btnRadius();
			width: 366rpx;
		}
	}

	.list {
		margin-top: 40rpx;
		width: 100%;
		display: flex;

		position: relative;
		flex-direction: column;
		align-items: center;

		&-item {
			margin-top: 14rpx;
			border-radius: 28rpx;
			background: #F1F9FF;
			width: 680rpx;
			height: 228rpx;
			box-sizing: border-box;
			padding: 22rpx 28rpx;
			position: relative;

			&-head {
				position: absolute;
				right: 30rpx;
				top: 20rpx;
				border-radius: 50%;
				width: 100rpx;
				height: 100rpx;
			}

			&-number {
				position: absolute;
				bottom: 34rpx;
				right: 20rpx;
				height: 52rpx;
				width: fit-content;
				margin-top: 18rpx;
				border-radius: 64rpx;
				background: #C4E4FC;
				box-sizing: border-box;
				padding: 12rpx 16rpx;
				@include center();
				color: #666;
				font-size: 28rpx;
			}

			&-class {
				height: 52rpx;
				width: fit-content;
				margin-top: 18rpx;
				border-radius: 64rpx;
				background: #C4E4FC;
				box-sizing: border-box;
				padding: 12rpx 16rpx;
				@include center();
				color: #666;
				font-size: 28rpx;
			}

			&-school {
				margin-top: 18rpx;
				color: #666;
				font-size: 28rpx;
			}

			&-sex {
				width: 32rpx;
				height: 32rpx;
				position: absolute;
				top: 30rpx;
				left: 160rpx;
				left: 200rpx;
			}

			&.selected {
				border: 2px solid #14AD61;
			}

			&-name {
				color: #1A1A1A;
				font-size: 36rpx;
			}

		}
	}

	.identity {
		margin-top: 50rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		position: relative;

		image {
			width: 648rpx;
			height: 232rpx;

			&:hover {
				border-radius: 28rpx;
				border: #14AD61 solid 2rpx;
			}
		}

		&-name {
			position: absolute;
			top: 50rpx;
			left: 420rpx;

			&-pinyin {
				color: #666;
				font-size: 28rpx;
			}

			&-text {
				font-size: 60rpx;
				color: $uni-color-title;
			}

		}
	}
</style>